﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using iLangl.Model;

namespace iLangl.LanguageWire
{
	public class JobInfo
	{
		public Int32 JobId { get; set; }
		public Int32 ParentJobId { get; set; }
		public Int32 Status { get; set; }
		public Int32 ResponsiblePerson { get; set; }
		public Translation Translation { get; set; }

		public Int32 JobType { get; set; }

		public JobInfo ParentJobInfo { get; set; }

		/// <summary>
		/// Childrens
		/// </summary>
		public Int32[] Jobs
		{
			get;
			set;
		}


		private JobInfo[] _jobInfos = null;
		/// <summary>
		/// Childres Jobs Info
		/// </summary>		
		public JobInfo[] JobInfos
		{
			get
			{
				return _jobInfos;
			}
			set
			{
				value = _jobInfos;
				foreach (JobInfo ji in JobInfos)
				{
					ji.ParentJobInfo = this;
				}
			}
		}

		public void AddChildren(JobInfo ji)
		{
			if (JobInfos == null)
			{
				JobInfos = new JobInfo[] { ji };
			}
			else
			{
				List<JobInfo> jobInfos = new List<JobInfo>();
				jobInfos.AddRange(JobInfos);
				jobInfos.Add(ji);
				JobInfos = jobInfos.ToArray();
			}
		}

		public bool IsParent()
		{
			return (ParentJobId <= 0);
		}
	}
}
